<?php
function post_to_url($url, $data) {
    $fields = '';
    foreach ($data as $key => $value) {
        $fields .= $key . '=' . $value . '&';
    }
    rtrim($fields, '&');
    $post = curl_init();
    curl_setopt($post, CURLOPT_SSLVERSION, 6);
    curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($post, CURLOPT_URL, $url);
    curl_setopt($post, CURLOPT_POST, count($data));
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($post); // result from SMS server
    curl_close($post);
    return $result;
}

function sendSingleSMS($username, $encryp_password, $senderid, $message, $mobileno, $deptSecureKey, $templateid) {
    $key = hash('sha512', trim($username) . trim($senderid) . trim($message) . trim($deptSecureKey));
    $data = array(
        "username" => trim($username),
        "password" => trim($encryp_password),
        "senderid" => trim($senderid),
        "content" => trim($message),
        "smsservicetype" => "singlemsg",
        "mobileno" => trim($mobileno),
        "key" => trim($key),
        "templateid" => trim($templateid)
    );
    return post_to_url("https://msdgweb.mgov.gov.in/esms/sendsmsrequestDLT", $data); // calling post_to_url to send SMS
}
?>
